package com.qianhui.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.qianhui.pojo.Manager;
import org.apache.struts2.ServletActionContext;

public class ManagerLoginInterceptor extends AbstractInterceptor
{

    @Override
    public String intercept(ActionInvocation invocation) throws Exception
    {
        String actionName = ServletActionContext.getActionMapping().getName();
        // 如果是登录、注册、退出的话就不要拦截了
        if (actionName.equals("exit") || actionName.equals("login") || actionName.equals("login_do") || actionName.equals("regist") || actionName.equals("regist_do"))
        {
            return invocation.invoke();
        }
		/*ManagerDAO managerDAO=new ManagerDAO();
		Manager managerFromDB=managerDAO.findById("test_id");
		ServletActionContext.getRequest().getSession().setAttribute("managerSession", managerFromDB);*/
        // 如果不是管理员就不能进入
        Manager managerTemp = (Manager) ServletActionContext.getRequest().getSession().getAttribute("managerSession");
        if (managerTemp == null)
        {
            return "manager_login";
        }
        return invocation.invoke();
    }

}
